package com.amado.easyui2.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.amado.easyui2.dao.CoachCarDao;
import com.amado.easyui2.domain.CoachCarEntity;
import com.amado.easyui2.exception.ApiException;
import com.amado.easyui2.enums.ApiErrorEnum;
import com.amado.easyui2.service.CoachService;
import com.amado.easyui2.vo.Page;
@Service
public class CoachServiceImpl implements CoachService {
	@Autowired
	private CoachCarDao coachDao;


	@Override
	public void add(CoachCarEntity lcn) {
		if(lcn==null) {
			throw new ApiException(ApiErrorEnum.ERROR_100);
		}
//		Lcn returnLcn=coachDao.
		CoachCarEntity returnLcn=coachDao.getByLcn(lcn.getLearnCardNumber());
		if(returnLcn!=null) {
			throw new ApiException(ApiErrorEnum.ERROR_1001);
		}
		coachDao.add(lcn);
	}

	@Override
	public CoachCarEntity getById(Long id) { 
		// TODO Auto-generated method stub
		return coachDao.getById(id);
	}

//	@Override
//	public void delete(Long id) {
//		// TODO Auto-generated method stub
//		coachDao.delete(id);
//	}

	@Override
	public void update(CoachCarEntity lcn) {
		// TODO Auto-generated method stub
		coachDao.update(lcn);
	}

	@Override
	public List<CoachCarEntity> list(String tm, String lcn) {
		// TODO Auto-generated method stub
		return coachDao.listAll(tm, lcn);
	}

	@Override
	public List<CoachCarEntity> getCoach(CoachCarEntity lcn) {
		// TODO Auto-generated method stub
		return coachDao.login(lcn);
	}

	@Override
	public Page<CoachCarEntity> listAll(String tm, String lcn, Page page) {
		int total = coachDao.listAllCount(tm, lcn);
		Page<CoachCarEntity> newPage  = new Page<>();
		newPage.setTotal(total);
		newPage.setRows(coachDao.listAll(tm, lcn,page));
		return newPage;
	}

	@Override
	public void delete(List<Long> id) {
		coachDao.delete(id);
		
	}

}
